﻿package com.gengine.resource.loader
{
    import com.gengine.debug.*;
    import com.gengine.resource.*;
    import com.gengine.resource.core.*;
    import com.gengine.resource.info.*;
    import flash.events.*;
    import flash.utils.*;

    public class BaseLoader extends StreamLoader
    {
        public var data:Object;
        protected var _resourceInfo:ResourceInfo;
        public var delayId:int = -1;

        public function BaseLoader()
        {
            return;
        }// end function

        public function getClass() : Class
        {
            return BaseLoader;
        }// end function

        public function get resourceInfo() : ResourceInfo
        {
            return this._resourceInfo;
        }// end function

        public function set resourceInfo(param1:ResourceInfo) : void
        {
            this._resourceInfo = param1;
            return;
        }// end function

        override protected function logMessage(param1:String) : void
        {
            Log.debug(param1);
            return;
        }// end function

        override public function initialize(param1) : void
        {
            super.initialize(param1);
            StreamManager.pushIn(this);
            return;
        }// end function

        public function load(param1:String, param2:ResourceInfo) : void
        {
            var _loc_3:ByteArray = null;
            if (param2)
            {
                _loc_3 = param2.cacheBytes;
                if (_loc_3)
                {
                    this._resourceInfo = param2;
                    this.initialize(_loc_3);
                    return;
                }
            }
            this._resourceInfo = param2;
            loadImp(param1);
            return;
        }// end function

        override protected function streamloadComplete(param1) : void
        {
            if (this._resourceInfo)
            {
                this._resourceInfo.cacheBytes = param1;
            }
            return;
        }// end function

        override protected function onIOErrorHandler(event:ErrorEvent) : void
        {
            if (this._resourceInfo)
            {
                this._resourceInfo.isLoaded = false;
                this._resourceInfo.isLoading = false;
            }
            var _loc_2:String = "";
            if (event)
            {
                _loc_2 = event.text;
            }
            dispatchEvent(new LoaderErrorEvent(_loc_2));
            super.onIOErrorHandler(event);
            return;
        }// end function

        override protected function onLoadCompleteHandler() : void
        {
            if (this._resourceInfo)
            {
                this._resourceInfo.isLoaded = true;
                this._resourceInfo.isLoading = false;
                this._resourceInfo.isHasLoaded = true;
                this._resourceInfo.resetDisposeTime();
                ResByteManager.addInfo(this._resourceInfo);
            }
            super.onLoadCompleteHandler();
            return;
        }// end function

        override public function dispose() : void
        {
            super.dispose();
            this._resourceInfo = null;
            return;
        }// end function

    }
}
